package com.lycx.businessmanager.manager;


import com.lycx.businessmanager.model.Sequence;
import com.lycx.businessmanager.service.ISequenceService;
import com.lycx.businessmanager.util.Look;

public class SequenceManager {

	private static ISequenceService sequenceService;

	public static ISequenceService getSequenceService() {
		if (sequenceService == null) {
			sequenceService = (ISequenceService) Look.up("sequenceService");
		}
		return sequenceService;
	}

	public static int createId(String tableName) {
		Sequence sequence = new Sequence();
		sequence.setTableName(tableName);
		sequence = getSequenceService().selectOne(sequence);
		if (sequence != null) {
			int newSeq = sequence.getSeq() + 1;
			sequence.setSeq(newSeq);
			getSequenceService().update(sequence);
			return newSeq;
		}

		return 0;
	}
}
